package org.mijia.dotsbox.core;

import java.io.File;
import java.util.HashMap;

public class Profile {

	private File profileUserDir;
	
	@SuppressWarnings("unchecked")
	private HashMap<Class, Dao> daoObjects = new HashMap<Class, Dao>();
	private EntityManager entityManager;
	
	public Profile(File userDir) {
		profileUserDir = userDir;
		if (!profileUserDir.exists() || !profileUserDir.isDirectory()) {
			profileUserDir.mkdirs();
		}
		
		entityManager = new EntityManager(new File(userDir, "data-index"));
	}
	
	public void dispose() {
		daoObjects.clear();
		
		if (entityManager != null) {
			entityManager.dispose();
		}
	}
	
	@SuppressWarnings("unchecked")
	public void bindDao(Dao dao, Class persistenceClass) {
		daoObjects.put(persistenceClass, dao);
		dao.setEntityManager(entityManager);
	}
	
	@SuppressWarnings("unchecked")
	public Dao getDao(Class persistenceClass) {
		return daoObjects.get(persistenceClass);
	}
}
